#!/bin/sh
################################################################################
## Copyright (c) International Business Machines  Corp., 2000                 ##
##                                                                            ##
## This program is free software;  you can redistribute it and/or modify      ##
## it under the terms of the GNU General Public License as published by       ##
## the Free Software Foundation; either version 2 of the License, or          ##
## (at your option) any later version.                                        ##
##                                                                            ##
## This program is distributed in the hope that it will be useful,            ##
## but WITHOUT ANY WARRANTY;  without even the implied warranty of            ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  ##
## the GNU General Public License for more details.                           ##
##                                                                            ##
## You should have received a copy of the GNU General Public License          ##
## along with this program;  if not, write to the Free Software Foundation,   ##
## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           ##
##                                                                            ##
################################################################################

do_setup()
{
	export RHOST="localhost"
	export TEST_USER_PASSWD="now_this_is_a_good_ltp_test_password"
	export TEST_USER_HOMEDIR="/home/$TEST_USER"

	tst_check_cmds expect ssh useradd userdel

	# erase user if he/she already exists, so we can have a clean env
	do_cleanup
	sleep 1

	if ! useradd -m -d "$TEST_USER_HOMEDIR" $TEST_USER; then
		tst_brkm TBROK "Failed to add user $TEST_USER to system $RHOST."
	fi

	echo "$TEST_USER:$TEST_USER_PASSWD" | chpasswd

	# create users home diretory (SLES 8 does not do this, even when
	# specified in adduser)
	if [ ! -d "$TEST_USER_HOMEDIR" ]; then
		USER_UID=$(id -u $TEST_USER)
		USER_GID=$(id -g $TEST_USER)
		if ! mkdir -p "$TEST_USER_HOMEDIR"; then
			tst_brkm TBROK "Failed to create $TEST_USER_HOMEDIR"
		fi
		chown -Rf $USER_UID.$USER_GID "$TEST_USER_HOMEDIR"
	fi
}

do_cleanup()
{
	userdel -r $TEST_USER 2> /dev/null
}
